define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'classes/teachers/index',
                    add_url: 'classes/teachers/add',
                    edit_url: 'classes/teachers/edit',
                    del_url: 'classes/teachers/del',
                    multi_url: 'classes/teachers/multi',
                    dragsort_url: '',
                    table: 'classes_teachersclasses',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'profile_id',
                sortName: 'profile_id',
                undefinedText: '无',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'user_id', title: __('UserId'),operate: false},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image,operate: false},
                        {field: 'realname', sortable: true, title: __('Realname'),operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'),operate: 'LIKE'},
                        {field: 'gender', sortable: true, title: __('Gender'),operate: false, sortable:true, formatter: function(value, row, index){
                                return value == 1 ? '男' : (value == 2 ? '女' : '未知')
                            }},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                search: false,
                commonSearch: true
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {

            Controller.api.bindevent();

        },
        edit: function () {

            Controller.api.bindevent();

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});